package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.common.core.utils.helper.StringHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.DdCouponUsed;
import com.ktgj.customer.service.IDdCouponUsedService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2022-09-28
 */
@RestController
@RequestMapping("/ddCouponUsed")
public class DdCouponUsedController extends BaseController
{
    @Autowired
    private IDdCouponUsedService ddCouponUsedService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize(hasPermi = "customer:used:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody DdCouponUsed ddCouponUsed)
    {
        startPage();
        List<DdCouponUsed> list = ddCouponUsedService.selectDdCouponUsedList(ddCouponUsed);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "customer:used:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DdCouponUsed ddCouponUsed) throws IOException
    {
        List<DdCouponUsed> list = ddCouponUsedService.selectDdCouponUsedList(ddCouponUsed);
        ExcelUtil<DdCouponUsed> util = new ExcelUtil<DdCouponUsed>(DdCouponUsed.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    @PostMapping("/uploadFile")
    public AjaxResult uploadFile(@RequestBody Map<String, String> map)
    {
        String filePath = map.get("filePath");
        if (StringHelper.isNullOrEmpty(filePath))
        {
            return AjaxResult.error("文件路径不能为空！");
        }
        boolean result;
        result = ddCouponUsedService.uploadCouponUsed(filePath);
        if (result)
        {
            return AjaxResult.success("上传使用记录成功！");
        }
        return AjaxResult.success("上传使用记录失败！");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "customer:used:query")
    @GetMapping(value = "/{couponUsedId}")
    public AjaxResult getInfo(@PathVariable("couponUsedId") Long couponUsedId)
    {
        return AjaxResult.success(ddCouponUsedService.selectDdCouponUsedById(couponUsedId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "customer:used:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DdCouponUsed ddCouponUsed)
    {
        return toAjax(ddCouponUsedService.insertDdCouponUsed(ddCouponUsed));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "customer:used:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DdCouponUsed ddCouponUsed)
    {
        return toAjax(ddCouponUsedService.updateDdCouponUsed(ddCouponUsed));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "customer:used:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponUsedIds}")
    public AjaxResult remove(@PathVariable Long[] couponUsedIds)
    {
        return toAjax(ddCouponUsedService.deleteDdCouponUsedByIds(couponUsedIds));
    }
}
